﻿using System;

namespace Nx.UI.Navigation
{
    public abstract class BaseNavigationTarget : INavigationTarget
    {
        public BaseNavigationTarget(object target)
        {
            _Target = target;
        }

        private object _Target;

        /// <summary>
        /// Gets the target and casts it to the target platform
        /// </summary>
        /// <typeparam name="T">Use System.Type on WinRT or System.Uri on Silverlight/Windows Phone</typeparam>
        /// <returns>The navigation target consumable by the internal NavigationFrame</returns>
        public T GetTarget<T>()
        {
            return (T)_Target;
        }

        public bool Equals(INavigationTarget other)
        {
            return this._Target.Equals(other.GetTarget<object>());
        }


        public static implicit operator Uri(BaseNavigationTarget target)
        {
            return target.GetTarget<Uri>();
        }

        public static implicit operator Type(BaseNavigationTarget target)
        {
            return target.GetTarget<Type>();
        }
    }

    public abstract class BaseNavigationTarget<T> : BaseNavigationTarget
    {
        public BaseNavigationTarget(T target)
            : base(target)
        {
        }

        internal T GetTarget()
        {
            return base.GetTarget<T>();
        }
    }
}
